package com.bwie.handler;

import com.bwie.utils.R;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: HaoSaiXin
 * @Date: 2025/7/17 19:35
 * @Description:
 **/
@ControllerAdvice
@Slf4j
public class GlobalException{

    /**
     * @author: HaoSaiXin
     * @description: 异常处理
     * @params: [java.lang.Exception]
     * @return: com.bwie.utils.R
     * @date: 2025/7/17 19:37
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public R error(Exception e) {
        log.info(e.getMessage());
        return R.ERROR(500, e.getMessage());
    }



    /**
     * @author: HaoSaiXin
     * @description:
     * @params: [java.lang.Exception]
     * @return: com.bwie.utils.R
     * @date: 2025/7/17 20:44
     */
    @ExceptionHandler(value = RuntimeException.class)
    public R errorRun(Exception e){
        return R.ERROR(500,e.getMessage());
    }
}
